home *** CD-ROM | disk | FTP | other *** search
/ AppleScript - The Beta Release / AppleScript - The Beta Release.iso / Documentation / develop / Better Apple Event Coding / Code Samples / UMAFailure.a < prev    next >
Encoding:
Text File  |  1992-10-16  |  4.2 KB  |  148 lines  |  [TEXT/MPS ]

  1. ;=============================================================================
  2. ; Failure Handler Assembly Routines
  3. ;
  4. ; KNOWN LIMITATIONS
  5. ;
  6. ; Copyright © 1984-1990 Apple Computer, Inc.  All rights reserved.
  7. ;
  8. ; when       who    what
  9. ; -------- ---- --------------------------------------------------------------
  10. ; 88.07.28 srf    add header and includes for Macros
  11. ; ----------------------------------------------------------------------------
  12.  
  13.                 Blanks        On
  14.                 String        AsIs
  15.                 Case        On
  16.  
  17.                 Print        Off
  18.  
  19.                 LOAD        'ProgStrucMacs.d'
  20.                 LOAD        'FlowCtlMacs.d'
  21.                 Print        On
  22.  
  23. ;---------------------------------------------------------------------------------------------------
  24.     Macro
  25.     Head
  26.         Link    A6,#0        ; These two instructions form a slow no-op
  27.         Move.L    (SP)+,A6
  28.     EndM
  29.  
  30.     Macro
  31.     Procnam &theName
  32.     String Asis
  33.  
  34.     LCLC        &DbgTemp
  35.     LCLC        &DbgName                            ; name to generate for MacsBug
  36.  
  37.     &DbgTemp: SETC    &theName                        ; Generate new type symbols
  38.     IF &Len(&theName) < 32 THEN                     ; If module name < 32 chars
  39.         IF &Len(&theName) // 2 = 0 THEN             ; Add space if even so that...
  40.             &DbgTemp: SETC &Concat(&theName,' ')    ; string length plus length byte...
  41.         ENDIF                                        ; will align to word boundary
  42.     &DbgName: SETC &Concat(&Chr($80 + &Len(&theName)), &DbgTemp)
  43.     ELSE                                            ; Length is greater than 32 characters
  44.         IF &Len(&theName) // 2 = 1 THEN             ; Add space if length is odd
  45.             &DbgTemp: SETC &Concat(&theName,' ')
  46.         ENDIF
  47.     &DbgName: SETC &Concat(&Chr($80), &Chr(&Len(&theName)), &DbgTemp)
  48.     ENDIF
  49.  
  50.     DC.B        '&DbgName'
  51.     EndM
  52.  
  53.     Macro
  54.     Tail &theName
  55.         Unlk    A6
  56.         Rts
  57.         PROCNAM &theName
  58.     EndM
  59.  
  60. ;---------------------------------------------------------------------------------------------------
  61.  
  62. UFailureGlobals Record
  63.                 Export        gAskAboutAlloc, gAskFailure
  64. gAskAboutAlloc    DC.W        0                    ; Boolean: ask about each allocation
  65. gAskFailure        DC.W        0                    ; Boolean: ask about failures
  66.                 EndR
  67.  
  68.  
  69. nSavedRegs        Equ         11
  70.  
  71.                 Seg         'MAFailureRes'
  72. ;-------------------------------------------------------------------
  73. ;PROCEDURE CatchFailures(VAR fi: FailInfo; PROCEDURE Handler(e: INTEGER; m: LONGINT)); EXTERNAL;
  74. ;-------------------------------------------------------------------
  75. CATCHFAILURES    Proc        Export
  76.                 DATA
  77.                 Export        gTopHandler:Data
  78. gTopHandler     DC.L        0            ;Pointer to the top level (most recent) handler
  79.                 CODE
  80.  
  81. A6Link            Equ         4                        ; static link which the Pascal compiler
  82.                                                     ; automatically pushes on the stack after
  83.                                                     ; pushing a ProcPtr ("PROCEDURE Handler")
  84. handler         Equ         A6Link + 4                ; the ProcPtr ("PROCEDURE Handler")
  85. fiVAR            Equ         handler + 4
  86. parmSize        Equ         fiVAR + 4 - A6Link
  87.  
  88.                 Head
  89.                 Move.L        fiVAR(SP),A0            ; get pointer to FailInfo block
  90.  
  91.                 MoveM.L     A2-A7/D3-D7,(A0)        ; save All regs first
  92.                 Add         #nSavedRegs*4,A0        ; advance pointer by # bytes regs
  93.  
  94.                 Clr.W        (A0)+                    ; clear error field
  95.                 Clr.L        (A0)+                    ; clear message field
  96.  
  97.                 Lea         A6Link(SP),A1            ; save the A6Link And Proc ptr
  98.                 Move.L        (A1)+,(A0)+             ; save the A6Link
  99.                 Move.L        (A1)+,(A0)+             ; save the Proc ptr
  100.  
  101.                 Move.L        gTopHandler(A5),(A0)+    ; Link the FailInfo into the LIST
  102.                 Move.L        fiVAR(SP),gTopHandler(A5)
  103.  
  104. exit
  105.                 Move.L        (SP)+,A0
  106.                 Add.L        #parmSize,SP
  107.                 Jmp         (A0)
  108.                 Tail        CATCHFAILURES
  109.  
  110.  
  111.                 Seg         'MAFailureRes'
  112. ;-------------------------------------------------------------------
  113. ;PROCEDURE DoFailure(pf: PFailInfo); EXTERNAL;
  114. ;-------------------------------------------------------------------
  115. DOFAILURE        Proc        Export
  116.                 Import        FAILURE
  117.  
  118. pf                Equ         4
  119.  
  120.                 Head
  121.                 Move.L        pf(SP),A0                ; get pointer to FailInfo
  122.                 MoveM.L     (A0),A2-A7/D3-D7        ; restore regs (can't use A7 anymore)
  123.                 Add         #nSavedRegs*4,A0        ; advance pointer
  124.  
  125.                 Move.W        (A0)+,D0                ; get error
  126.                 Move.L        (A0)+,D1                ; And message
  127.                 MoveM.L     D0/D1,-(SP)             ; save for later use
  128.  
  129.                 Move.W        D0,-(SP)
  130.                 Move.L        D1,-(SP)                ; parameters to failure handler
  131.  
  132.                 Move.L        (A0)+,D0                ; check the A6Link
  133.                 Beq.S        @1                        ; If NIL Then don't pass it
  134.                 Move.L        D0,-(SP)                ; Else Do pass it
  135. @1
  136.                 Move.L        (A0)+,A0                ; get address of failure handler
  137.  
  138.                 Jsr         (A0)                    ; call failure handler
  139.                 MoveM.L     (SP)+,D0/D1             ; get error & message back
  140.                 Move.W        D0,-(SP)
  141.                 Move.L        D1,-(SP)                ; parameters to Failure
  142.                 Jsr         FAILURE
  143.  
  144.                 ; should Not return
  145.                 Tail    DOFAILURE
  146.  
  147.                 End
  148.